import {
  createRouter,
  createWebHistory,
  RouteRecordRaw,
  createWebHashHistory,
  Router,
} from 'vue-router'
import Layout from '@/layout/index.vue'
// 扩展继承属性
interface extendRoute {
  hidden?: boolean
}
//

import errorRouter from './modules/error'

// 异步组件
export const asyncRoutes = [
  ...errorRouter,
  {
    path: '/:pathMatch(.*)',
    redirect: '/404',
  },
]

/**
 * path ==> 路由路径
 * name ==> 路由名称
 * component ==> 路由组件
 * redirect ==> 路由重定向
 * alwaysShow ==> 如果设置为true，将始终显示根菜单，无论其子路由长度如何
 * hidden ==> 如果“hidden:true”不会显示在侧边栏中（默认值为false）
 * keepAlive ==> 设为true 缓存
 * meta ==> 路由元信息
 * meta.title ==> 路由标题
 * meta.icon ==> 菜单icon
 * meta.affix ==> 如果设置为true将会出现在 标签栏中
 * meta.breadcrumb ==> 如果设置为false，该项将隐藏在breadcrumb中（默认值为true）
 */

export const constantRoutes: Array<RouteRecordRaw & extendRoute> = [
  {
    path: '/loginFirst',
    name: 'LoginFirst',
    component: () => import('@/views/loginFirst/index.vue'),
    hidden: true,
    meta: { title: '首次登录' },
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index.vue'),
    hidden: true,
    meta: { title: '登录' },
  },
  {
    path: '/',
    name: 'layout',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: '/home',
        component: () => import('@/views/home/index.vue'),
        name: 'home',
        meta: { title: '首页', icon: 'House' },
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/enterParty',
    meta: { title: '入党流程', icon: 'Position' },
    children: [
      {
        path: 'application',
        component: () => import('@/views/enterParty/components/application.vue'),
        name: 'application',
        meta: { title: '申请入党', icon: 'Bottom' },
      },
      {
        path: 'activists',
        component: () => import('@/views/enterParty/components/activists.vue'),
        name: 'activists',
        meta: { title: '入党积极分子', icon: 'Bottom' },
      },
      {
        path: 'developer',
        component: () => import('@/views/enterParty/components/developer.vue'),
        name: 'developer',
        meta: { title: '入党发展对象', icon: 'Bottom' },
      },
      {
        path: 'accept',
        component: () => import('@/views/enterParty/components/accept.vue'),
        name: 'accept',
        meta: { title: '预备党员接收', icon: 'Bottom' },
      },
      {
        path: 'investigation',
        component: () => import('@/views/enterParty/components/investigation.vue'),
        name: 'investigation',
        meta: { title: '预备党员考察', icon: 'Bottom' },
      },
    ],
  },

  {
    path: '/',
    component: Layout,
    redirect: '/information',
    children: [
      {
        path: '/information',
        component: () => import('@/views/personalInformation/index.vue'),
        name: 'information',
        meta: { title: '个人信息中心', icon: 'UserFilled' },
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/fee',
    children: [
      {
        path: '/fee',
        component: () => import('@/views/QRcode/index.vue'),
        name: 'fee',
        meta: { title: '党费提交', icon: 'Money' },
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/notice',
    children: [
      {
        path: '/notice',
        component: () => import('@/views/notice/index.vue'),
        name: 'notice',
        meta: { title: '个人通知', icon: 'ChatLineSquare' },
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/activity',
    children: [
      {
        path: '/activity',
        component: () => import('@/views/partyActivity/index.vue'),
        name: 'activity',
        meta: { title: '党建活动', icon: 'List' },
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/documentApproval',
    children: [
      {
        path: '/documentApproval',
        component: () => import('@/views/documentApproval/index.vue'),
        name: 'documentApproval',
        meta: { title: '文件审核', icon: 'Message' },
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/activityDetail',
    hidden: true,
    children: [
      {
        path: '/activityDetail',
        component: () => import('@/views/activityDetail/index.vue'),
        name: 'activityDetail',
        meta: { title: '公告详情', icon: 'MoreFilled' },
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/noticeDetail',
    hidden: true,
    children: [
      {
        path: '/noticeDetail',
        component: () => import('@/views/noticeDetail/index.vue'),
        name: 'noticeDetail',
        meta: { title: '通知详情', icon: 'Sunset' },
      },
    ],
  },
  {
    path: '/',
    component: Layout,
    redirect: '/outerAPI',
    hidden: false,
    meta: { title: '看看展馆', icon: 'Sunset' },
    children: [
      {
        path: '/first',
        component: () => import('@/views/outerAPI/components/first.vue'),
        name: 'first',
        meta: { title: '奋进新时代', icon: 'View' },
      },
      {
        path: '/second',
        component: () => import('@/views/outerAPI/components/second.vue'),
        name: 'second',
        meta: { title: '中共三大会址', icon: 'View' },
      },
      {
        path: '/third',
        component: () => import('@/views/outerAPI/components/third.vue'),
        name: 'third',
        meta: { title: '广州起义', icon: 'View' },
      },
    ],
  },
]

const router = createRouter({
  // history: createWebHistory(process.env.BASE_URL), // history
  history: createWebHashHistory(), // hash
  routes: constantRoutes,
})

export default router
